package com.restaurant.application.indexes.accumulatelist.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class AccumulateListData implements PickableBean {

    public static final String FN_DETAIL = "detail";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_DETAIL);

    private String detail;

    public AccumulateListData(String detail) {
        setDetail(detail);
    }

    public AccumulateListData() {
    }

    public AccumulateListData duplicate() {
        AccumulateListData result = new AccumulateListData();
        result.detail = this.detail;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String value) {
        this.detail = value;
    }

    public AccumulateListData withDetail(String value) {
        setDetail(value);
        return this;
    }

    public AccumulateListData withDetail(String value, String defaultValue) {
        setDetail(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "detail":
                return getDetail();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof AccumulateListData)) return false;
        return signature().equals(((AccumulateListData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean AccumulateListData has no signature defined, no hash code or equals possible.");
    }
}
